package com.nuoniu.sibanyun.mapper.provider;

import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.entity.crm.CrmDefineField;
import com.nuoniu.sibanyun.entity.dto.SysLogDto;
import org.apache.ibatis.jdbc.SQL;

/**
 * @auther 小啊刚
 * @date 2020/5/23
 */
public class CrmDefineFieldMapperProvider {

    /**对应数据库表名**/
    private String TABLE_NAME = "crm_define_field";

    /**
     * 获取字段列表
     * @author 小啊刚
     * @date 2020/5/23
     */
    public String findList(CrmDefineField field) {
        return new SQL() {
            {
                SELECT("*");
                FROM(TABLE_NAME);
                if(field.getDataType() != null) {
                    WHERE("data_type = #{dataType}");
                }
                if(field.getStatus() != null) {
                    WHERE("status = #{status}");
                }
                if(StringUtils.isNotBlank(field.getSource())) {
                    WHERE("source = #{source}");
                }
                WHERE("company_id = #{companyId}");
                ORDER_BY("sort");
            }
        }.toString();
    }
}
